import React, { useEffect, useState } from "react";
import request from "@/utils/request";
import { message, Card, Col, Row, Statistic } from "antd";
import { ChartCard } from './Charts';
const MinerTotal = (props) => {
  const {
    MinerId
  } = props;
  const [data, dataUpdate] = useState({})
  useEffect(() => {
    request(`/api/index/get?MinerId=${MinerId}`).then(res => {
      if (res.Code != 0) {
        message.error(res.Msg)
      }
      console.log(res)
      if (res.Data) {
        dataUpdate(res.Data)
      }
    })
  }, [MinerId])


    if (!data.DoneYesterdaySyncTotal) {
      data.TodayRewardCount = "-"
      data.TodayRoundWinner = "-"
      data.YesterdayRewardCount = "-"
      data.YesterdayRoundWinner = "-"
    }else{
      data.TodayRewardCount = data.TodayRewardCount.toString()
      data.TodayRoundWinner = data.TodayRoundWinner.toString()
      data.YesterdayRewardCount = data.YesterdayRewardCount.toString()
      data.YesterdayRoundWinner = data.YesterdayRoundWinner.toString()
    }

    if (!data.DoneRoundWinner) {
      data.TodayRoundWinner = "-"
      data.YesterdayRoundWinner = "-"
    }

    if(!data.DoneYesterdaySyncMsg){
      data.TodayPowerGrowth = "-"
      data.ExpectIncreaseComputingPower = "-"
    }else{
      data.TodayPowerGrowth = data.TodayPowerGrowth.toFixed(2).toString()
      data.ExpectIncreaseComputingPower = data.ExpectIncreaseComputingPower.toFixed(2).toString()
    }

  return (
    <>

      <Row gutter={24}>
        <Col
          xl={24}
          lg={24}
          md={24}
          sm={24}
          xs={24}
          style={{
            marginBottom: 24,
          }}
        >
          <Card
            title={"矿工基本信息"}
            bordered={false}
          >
            <div className="site-statistic-demo-card">
              <Row gutter={[16, 16]}>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="矿工余额"
                      value={data.DoneYesterdaySyncTotal ? data.TotalBalanceFloat.toFixed(2) : "-"}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="有效算力"
                      value={data.DoneYesterdaySyncTotal ? data.QualityAdjPowerFloat.toFixed(2): "-"}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "TiB" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="算力占比"
                      value={data.DoneYesterdaySyncTotal ? data.PowerRatio.toFixed(2): "-"}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "%" : ""}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <Card>
                    <Statistic
                      title="累计出块数"
                      value={data.IsSyncAllRewardCount && data.DoneYesterdaySyncTotal ? data.RewardCount : "-"}
                      valueStyle={{ color: '#3f8600' }}
                      suffix=""
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="累计出块奖励"
                      value={data.IsSyncAllRewardCount ? data.RewardNumsFloat.toFixed(2): "-"}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.IsSyncAllRewardCount && data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>


                <Col span={8}>
                  <Card>
                    <Statistic
                      title="时空证明数"
                      value={data.DoneYesterdaySyncTotal ? data.ProvingDeadlines: "-"}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="错误扇区数"
                      value={data.DoneYesterdaySyncTotal ? data.FaultySectors: "-"}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </Card>
                </Col>

                <Col span={16}>
                  <Card>
                    <Statistic
                      title="高度"
                      value={data.DoneYesterdaySyncTotal ? data.Height: "-"}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </Card>
                </Col>
              </Row>
            </div>
          </Card>
        </Col>
      </Row>


      <Row gutter={24}>
        <Col
          xl={24}
          lg={24}
          md={24}
          sm={24}
          xs={24}
          style={{
            marginBottom: 24,
          }}
        >
          <Card
            title={"矿工收入信息"}
            bordered={false}
          >
            <div className="site-statistic-demo-card">
              <Row gutter={[16, 16]}>
                <Col span={8}>
                  <ChartCard
                    footer={
                      <div>
                        {
                          !data.DoneYesterdaySyncTotal ?
                            `赢块率:- 幸运值:- `
                            :
                            ''
                        }
                        {data.DoneYesterdaySyncTotal && data.TodayWinPerDay ? `赢块率:${data.TodayWinPerDay.toFixed(2)} ` : ` `}
                        {data.DoneYesterdaySyncTotal && data.TodayWinPerDay ? `幸运值:${data.TodayLucky.toFixed(2)}% ` : ``}

                      </div>
                    }>
                    <Statistic
                      title="今天出块数 / 今天出块权"
                      value={data.TodayRewardCount +" / "+ data.TodayRoundWinner}
                      valueStyle={{ color: '#3f8600', marginBottom: 0 }}
                    />
                  </ChartCard>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="今天出块奖励"
                      value={data.DoneYesterdaySyncTotal ? data.TodayRewardFil.toFixed(2): '-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="今天出块收益"
                      value={data.DoneYesterdaySyncTotal ? data.TodayEveryTibEarnings.toFixed(2): '-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL/TiB" : ""}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <Card>
                    <Statistic
                      title="今天释放FIL"
                      value={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? data.TodayReleaseFil.toFixed(2): '-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="今天立即释放"
                      value={data.DoneYesterdaySyncTotal ? data.TodayImmediateRelease.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="今天线性释放"
                      value={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? data.TodayVesting.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <ChartCard
                    footer={
                      <div>
                        {
                          !data.DoneYesterdaySyncTotal ?
                            `赢块率:- 幸运值:- `
                            :
                            ''
                        }
                        {data.DoneYesterdaySyncTotal && data.YesterdayWinPerDay ? `赢块率:${data.YesterdayWinPerDay.toFixed(2)} ` : ` `}
                        {data.DoneYesterdaySyncTotal && data.YesterdayLucky ? `幸运值:${data.YesterdayLucky.toFixed(2)}% ` : ``}
                      </div>
                    }>
                    <Statistic
                      title="昨天出块数 / 昨天出块权"
                      value={data.YesterdayRewardCount +" / "+ data.YesterdayRoundWinner}
                      valueStyle={{ color: '#3f8600' }}
                      suffix=""
                    />
                  </ChartCard>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="昨天出块奖励"
                      value={data.DoneYesterdaySyncTotal ? data.YesterdayRewardFil.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <Card>
                    <Statistic
                      title="昨天出块收益"
                      value={data.DoneYesterdaySyncTotal ? data.YesterdayEveryTibEarnings.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL/TiB" : ""}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <Card>
                    <Statistic
                      title="昨天释放FIL"
                      value={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? data.YesterdayReleaseFil.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="昨天立即释放"
                      value={data.DoneYesterdaySyncTotal ? data.YesterdayImmediateRelease.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="昨天线性释放"
                      value={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? data.YesterdayVesting.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneSyncVestingFunds && data.DoneYesterdaySyncTotal ? "FIL" : ""}
                    />
                  </Card>
                </Col>
              </Row>
            </div>
          </Card>
        </Col>
      </Row>

      <Row gutter={24}>
        <Col
          xl={24}
          lg={24}
          md={24}
          sm={24}
          xs={24}
          style={{
            marginBottom: 24,
          }}
        >
          <Card
            title={"矿工支出信息"}
            bordered={false}
          >
            <div className="site-statistic-demo-card">
              <Row gutter={[16, 16]}>
                <Col span={6}>
                  <ChartCard
                    footer={
                      <div>
                        {
                          !data.DoneYesterdaySyncMsg ?
                            `抵押:- Gas:- `
                            :
                            ''
                        }
                        {data.DoneYesterdaySyncMsg ? `抵押:${data.TodayPledge.toFixed(2)} ` : ``}
                        {data.DoneYesterdaySyncMsg ? `Gas:${data.TodayGas.toFixed(2)}% ` : ``}

                      </div>
                    }>
                    <Statistic
                      title="今天消耗FIL"
                      value={data.DoneYesterdaySyncMsg ? data.TodayReductionsBalances.toFixed(2):'-'}
                      precision={2}
                      suffix={data.DoneYesterdaySyncMsg ? "FIL" : ""}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </ChartCard>
                </Col>
                <Col span={6}>
                  <Card>
                    <Statistic
                      title="今天密封算力 / 今天预估密封算力"
                      value={data.TodayPowerGrowth+" / "+ data.ExpectIncreaseComputingPower}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncMsg ? "TiB" : ""}
                    />
                  </Card>
                </Col>
                <Col span={6}>
                  <ChartCard
                    footer={
                      <div>
                        {
                          !data.DoneYesterdaySyncMsg ?
                            `抵押:- Gas:- `
                            :
                            ''
                        }
                        {data.DoneYesterdaySyncMsg ? `抵押:${data.TodayCostPerTibByPledge.toFixed(2)} ` : ``}
                        {data.DoneYesterdaySyncMsg ? `Gas:${data.TodayCostPerTibByGas.toFixed(2)}% ` : ``}

                      </div>
                    }>
                    <Statistic
                      title="今天密封成本"
                      value={data.DoneYesterdaySyncMsg ? data.TodayCostPerTib.toFixed(2):'-'}
                      suffix={data.DoneYesterdaySyncMsg ? "FIL/TiB" : ""}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </ChartCard>
                </Col>
                <Col span={6}>
                  <Card>
                    <Statistic
                      title="今天罚币"
                      value={data.DoneYesterdaySyncMsg ? data.TodayBurnFil.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncMsg ? "FIL" : ""}
                    />
                  </Card>
                </Col>
                <Col span={6}>
                  <ChartCard
                    footer={
                      <div>
                        {
                          !data.DoneYesterdaySyncMsg ?
                            `抵押:- Gas:- `
                            :
                            ''
                        }
                        {data.DoneYesterdaySyncMsg ? `抵押:${data.YesterdayPledge.toFixed(2)} ` : ``}
                        {data.DoneYesterdaySyncMsg ? `Gas:${data.YesterdayGas.toFixed(2)}% ` : ``}

                      </div>
                    }>
                    <Statistic
                      title="昨天消耗FIL"
                      value={data.DoneYesterdaySyncMsg ? data.YesterdayReductionsBalances.toFixed(2):'-'}
                      precision={2}
                      suffix={data.DoneYesterdaySyncMsg ? "FIL" : ""}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </ChartCard>
                </Col>

                <Col span={6}>
                  <Card>
                    <Statistic
                      title="昨天密封算力"
                      value={data.DoneYesterdaySyncMsg ? data.YesterdayPowerGrowth.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncMsg ? "TiB" : ""}
                    />
                  </Card>
                </Col>

                <Col span={6}>
                  <ChartCard
                    footer={
                      <div>
                        {
                          !data.DoneYesterdaySyncMsg ?
                            `抵押:- Gas:- `
                            :
                            ''
                        }
                        {data.DoneYesterdaySyncMsg ? `抵押:${data.YesterdayCostPerTibByPledge.toFixed(2)} ` : ``}
                        {data.DoneYesterdaySyncMsg ? `Gas:${data.YesterdayCostPerTibByGas.toFixed(2)}% ` : ``}

                      </div>
                    }>
                    <Statistic
                      title="昨天密封成本"
                      value={data.DoneYesterdaySyncMsg ? data.YesterdayCostPerTib.toFixed(2):"-"}
                      precision={2}
                      suffix={data.DoneYesterdaySyncMsg ? "FIL/TiB" : ""}

                      valueStyle={{ color: '#3f8600' }}
                    />
                  </ChartCard>
                </Col>
                <Col span={6}>
                  <Card>
                    <Statistic
                      title="昨天罚币"
                      value={data.DoneYesterdaySyncMsg ? data.YesterdayBurnFil.toFixed(2):'-'}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix={data.DoneYesterdaySyncMsg ? "FIL" : ""}
                    />
                  </Card>
                </Col>
              </Row>
            </div>
          </Card>
        </Col>
      </Row>


    </>
  )
};

export default MinerTotal;
